package com.whalehearing.tingyou.api.controller.hearing;

import com.whalehearing.tingyou.common.annotation.DataSource;
import com.whalehearing.tingyou.common.annotation.Log;
import com.whalehearing.tingyou.common.core.controller.BaseController;
import com.whalehearing.tingyou.common.core.domain.AjaxResult;
import com.whalehearing.tingyou.common.enums.BusinessType;
import com.whalehearing.tingyou.common.enums.DataSourceType;
import com.whalehearing.tingyou.dto.HearingAudiogramDTO;
import com.whalehearing.tingyou.service.IHearingAudiogramService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.List;
import java.util.Map;

/**
 * 听力档案Controller
 *
 * @author zengjun-qxm
 * @date 2024-09-13
 */
@Api(tags = "api听力档案管理")
@RestController
@RequestMapping("/api/hearing/audiogram")
public class ApiHearingAudiogramController extends BaseController {
    @Autowired
    private IHearingAudiogramService hearingAudiogramService;

    /**
     * 根据-userId-查询用户名-用于听力检测首页展示
     */
    @ApiOperation("根据-userId-查询用户名-用于听力检测首页展示")
    @GetMapping(value = "/getUserNameByUserId/{userId}")
    public AjaxResult getUserNameByUserId(@PathVariable Long userId) {
        return success(hearingAudiogramService.getUserNameByUserId(userId));
    }


    /**
     * 新增听力档案
     */
    @ApiOperation("新增听力档案")
    @Log(title = "听力档案", businessType = BusinessType.INSERT)
    @PostMapping("/saveAudiogram")
    public AjaxResult add(@RequestBody HearingAudiogramDTO hearingAudiogramDTO) {
        return AjaxResult.success(hearingAudiogramService.saveAudiogram(hearingAudiogramDTO));
    }

    /**
     * 根据-userId-查询听力档案列表
     */
    @ApiOperation("根据-userId-查询听力档案列表")
    @GetMapping("/getAudiogramListByUserId/{userId}")
    public AjaxResult getAudiogramListByUserId(@PathVariable Long userId) {
        List<Map<String, Object>> audiogramList = hearingAudiogramService.getAudiogramListByUserId(userId);
        return success(audiogramList);
    }

    /**
     * 根据-audiogramId-获取听力档案详细信息
     */
    @ApiOperation("根据-audiogramId-获取听力档案详细信息")
    @GetMapping(value = "/getAudiogramInfoByAudiogramId/{audiogramId}")
    public AjaxResult getAudiogramInfoByAudiogramId(@PathVariable("audiogramId") Long audiogramId) {
        HearingAudiogramDTO audiogramInfo = hearingAudiogramService.getAudiogramInfoByAudiogramId(audiogramId);
        return success(audiogramInfo);
    }


    /**
     * 删除听力档案
     */
    @ApiOperation("删除听力档案")
    @Log(title = "听力档案", businessType = BusinessType.DELETE)
    @DeleteMapping("/deleteAudiogram/{audiogramIds}")
    public AjaxResult remove(@PathVariable Long[] audiogramIds) {
        return toAjax(hearingAudiogramService.removeByIds(Arrays.asList(audiogramIds)));
    }

    /**
     * 根据-推荐记录id-获取听力档案id-用户的年龄等信息
     */
    @ApiOperation("根据-推荐记录id-获取听力档案id-用户的年龄等信息")
    @GetMapping(value = "/getInfoByRecommendId/{id}")
    public AjaxResult getInfoByRecommendId(@PathVariable("id") Long id) {
        HearingAudiogramDTO audiogramInfo = hearingAudiogramService.getInfoByRecommendId(id);
        return success(audiogramInfo);
    }
}
